﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HRMS_Model;
using System.ComponentModel.DataAnnotations;

namespace HRMS.Models
{
    public class Users
    {
        public static User ValidateUser(string userName, string password)
        {
            using (HRMSEntities signInEntity = new HRMSEntities())
            {
                var validUser = signInEntity.Users.FirstOrDefault(u => u.UserName == userName && u.Password == password);
                return validUser;
            }
        }

        public static void AddUser(User user)
        {
            using (var usrEntity = new HRMSEntities())
            {
                usrEntity.Users.AddObject(user);
                usrEntity.SaveChanges();
            }
        }
        public static void DeleteUser(User userObj)
        {
            using (HRMSEntities userEntity = new HRMSEntities())
            {
                User user = new User();
                user.UserName = userObj.UserName;
                user.Role = userObj.Role;
                user.Password = userObj.Password;
                user.Active = userObj.Active;

                userEntity.Users.DeleteObject(user);

            }
        }
    }
}